package com.ruoyi.web.controller.wexin;



import com.ruoyi.weixin.anno.ILog;
import com.ruoyi.weixin.anno.RequireLogin;
import com.ruoyi.weixin.entity.Account;
import com.ruoyi.weixin.entity.R;
import com.ruoyi.weixin.service.AccountsService;
import com.ruoyi.weixin.vo.AccountPararm;
import com.ruoyi.weixin.vo.Paihang;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;

/**
 * (Account)表控制层
 *
 * @author makejava
 * @since 2024-01-02 17:19:56
 */

@RestController
@RequestMapping("/wexinLogin/account")
public class AccountsController {
    /**
     * 服务对象
     */
    @Resource
    private AccountsService accountService;

    @PostMapping
    public R selectAll(@RequestBody AccountPararm accountPararm) throws ParseException {
        return R.ok(accountService.accountList(accountPararm));
    }

    @PostMapping("selectPaihang")
    public R selectPaihang(@RequestBody Paihang paihang) {
        return R.ok(accountService.selectPaihang(paihang));
    }

    @PostMapping("yearAcount")
    public R yearAcount(@RequestBody Paihang paihang) {
        return R.ok(accountService.yearAcount(paihang));
    }

    @PostMapping("accountTbList")
    public R accountTbList(String type) {
        return R.ok(accountService.accountTbList(type));
    }

    @ILog("添加/修改账单")
    @PostMapping("accountAdd")
    public R accountAdd(@RequestBody Account account) {
        boolean b;
        if (account.getId()!=null){
              b = accountService.updateById(account);
        }else {
              b = accountService.save(account);
        }
        return R.ok(b);
    }
    @ILog("删除账单")
    @PostMapping("accountDelete")
    public R accountDelete(String id) {
        return R.ok(accountService.removeById(id));
    }

    @PostMapping("getCode")
    public R getCode(String userId) {
        return R.ok(accountService.getCode(userId));
    }


    @PostMapping("checkCode")
    public R checkCode(String userId,String code) {
        return R.ok(accountService.checkCode(userId,code));
    }

    @PostMapping("checkUser")
    public R checkUser(String userId) {
        return R.ok(accountService.checkUser(userId));
    }
}

